<!-- user表单弹窗 -->
<form id="mask-form" lay-filter="mask-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">算法</label>
        <div class="layui-input-block">
            <select name="name" lay-verify="required">
                <option value="dx_pad">pad</option>
                <option value="dx_replace">replace</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字段索引</label>
        <div class="layui-input-block">
            <select name="columnIndex" id="columnIndex" class="layui-input" lay-verify="required">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开始位置</label>
        <div class="layui-input-block">
            <input name="start" placeholder="请输入开始位置" type="text" class="layui-input" lay-verify="required"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字段长度</label>
        <div class="layui-input-block">
            <input name="length" placeholder="请输入字段长度" type="text" class="layui-input" lay-verify="required"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">替换字符</label>
        <div class="layui-input-block">
            <input name="chars" placeholder="替换的字符" type="text" class="layui-input" lay-verify="required"/>
        </div>
    </div>

    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary close" type="button">取消</button>
        <button class="layui-btn" lay-filter="user-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'crown', 'form', 'element'], function () {
        var layer = layui.layer;
        var crown = layui.crown;
        var form = layui.form;
        var $ = layui.jquery;

        var mask = crown.getTempData('t_mask');
        if(mask){
            var params = {
                "taskId": mask.taskId,
                "tableName": mask.tableName
            };
            crown.get('/task/columns', params, function(response){
                var items = response.data;
                for(var i = 0; i< items.length; i++){
                    $('#columnIndex').append(new Option(items[i], i));
                }
                form.render();
            });
        }


        form.on('submit(user-form-submit)', function (data) {
            layer.load(2);
            var items = data.field;
            items['taskId'] = mask.taskId;
            items['tableName'] = mask.tableName;
            crown.post('/mask/create', items, function () {
                layer.closeAll('loading');
                layer.msg('添加成功', {icon: 1});
                //crown.finishPopupCenter();
            });
            return false;
        });
    });
</script>